package database_interaction;

/**
 * @file SelectQuery.java
 *
 * @version 0.1
 * @author James Dibble 10009689
 */
public class SelectQuery extends SQLQuery {
    // <editor-fold defaultstate="collapsed" desc="Attributes">
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructors">
    public SelectQuery(String table) {
        super(QueryType.SELECT, table);
    }
    
    public SelectQuery(String table, String filter) throws JDBCException {
        super(QueryType.SELECT, table);
        super.setFilter(filter);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Methods">
    @Override
    public String getQueryString() throws JDBCException {
        String strColumns = "";
        if (super._parms.getColumns().isEmpty()) {
            strColumns = "*";
        } else {
            for (String thisCol : super._parms.getColumns()) {
                strColumns += thisCol + ",";
            }
            strColumns = strColumns.substring(0, strColumns.length() - 1);
        }
        if(!"".equals(super.getFilter()) || super.getFilter() != null)
            return String.format("SELECT %s FROM %s WHERE %s",
                             strColumns,
                             super.getTable(),
                             super.getFilter());
        else
            return String.format("SELECT %s FROM %s",
                                strColumns,
                                super.getTable());
    }
    // </editor-fold>    
}